package com.xubao.ali.controller.copyright;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xubao.ali.services.BooksService;
import com.xubao.ali.services.PrintWriterService;
import com.xubao.ali.utils.ReturnUtil;

/**
 * Servlet implementation class DetailController
 */
public class DetailController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	BooksService bss = new BooksService();
	
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String bookid = request.getParameter("bid");
		System.out.println(bookid);
		if(bookid != null) {
			List list = bss.findDetailById(Integer.parseInt(bookid));
			if(list.isEmpty()) {
				PrintWriterService.send(response, ReturnUtil.ISEMPTY);
			}else {
				PrintWriterService.send(response, list);
			}
		}else {
			PrintWriterService.send(response, ReturnUtil.PARAMERROR);
		}
	}

}
